const {
  getallmessage,
  reply,
  deletereply,
  changethumb,
  mangetallmessage,
} = require("../services/message.services");

class Messagecontroller {
  //获取所有留言
  async getallmessage(ctx) {
    try {
      const result = await getallmessage();
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
  //回复留言
  async reply(ctx) {
    const body = ctx.request.body;
    try {
      const result = await reply(body);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
  //删除留言
  async deletereply(ctx) {
    const id = ctx.params.id;
    try {
      const result = await deletereply(id);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
  //点赞或取消点赞
  async changethumb(ctx) {
    const body = ctx.request.body;
    try {
      const result = await changethumb(body);
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }

  //管理员获得获取所有留言
  async mangetallmessage(ctx) {
    try {
      const result = await mangetallmessage();
      ctx.body = result;
    } catch (e) {
      console.log(e);
      ctx.body = e.message;
    }
  }
}

module.exports = new Messagecontroller();
